# Dockerfile for Ubuntu 16.04 manylinux2010 custom ops with GPU.

FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu16.04 as devtoolset

LABEL maintainer="Amit Patankar <amitpatankar@google.com>"

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
      cpio \
      file \
      flex \
      g++ \
      make \
      rpm2cpio \
      unar \
      wget \
      && \
    rm -rf /var/lib/apt/lists/*

ADD devtoolset/fixlinks.sh fixlinks.sh
ADD devtoolset/build_devtoolset.sh build_devtoolset.sh
ADD devtoolset/rpm-patch.sh rpm-patch.sh

# Set up a sysroot for glibc 2.12 / libstdc++ 4.4 / devtoolset-7 in /dt7.
RUN /build_devtoolset.sh devtoolset-7 /dt7
# Set up a sysroot for glibc 2.12 / libstdc++ 4.4 / devtoolset-8 in /dt8.
RUN /build_devtoolset.sh devtoolset-8 /dt8

# TODO(klimek): Split up into two different docker images.
FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu16.04

LABEL maintainer="Amit Patankar <amitpatankar@google.com>"

COPY --from=devtoolset /dt7 /dt7
COPY --from=devtoolset /dt8 /dt8

# Install TensorRT.
RUN apt-get update && apt-get install -y \
    libnvinfer-dev=6.0.1-1+cuda10.1 \
    libnvinfer6=6.0.1-1+cuda10.1 \
    libnvinfer-plugin-dev=6.0.1-1+cuda10.1 \
    libnvinfer-plugin6=6.0.1-1+cuda10.1 \
      && \
    rm -rf /var/lib/apt/lists/*

# Copy and run the install scripts.
COPY install/*.sh /install/
ARG DEBIAN_FRONTEND=noninteractive
RUN /install/install_bootstrap_deb_packages.sh
RUN /install/install_deb_packages.sh
RUN /install/install_clang.sh
RUN /install/install_bazel.sh
RUN /install/install_buildifier.sh

ENV TF_NEED_CUDA=1

# Install python 3.6.
RUN add-apt-repository ppa:deadsnakes/ppa && \
    apt-get update && apt-get install -y \
    python3.6 python3.6-dev python3-pip python3.6-venv && \
    rm -rf /var/lib/apt/lists/* && \
    python3.6 -m pip install pip --upgrade && \
    update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 0

# Install python 3.7
RUN /install/install_python37.sh

# Install pip3.6
RUN wget https://bootstrap.pypa.io/get-pip.py && python3.6 get-pip.py && rm get-pip.py

RUN /install/install_pip_packages.sh
RUN /install/install_auditwheel.sh

# Make python3.6 the default python version
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.6 0

# Install given tensorflow or tf-nightly version, if not specified, install the # latest official release
ARG TF_PACKAGE=tensorflow
ARG TF_PACKAGE_VERSION=
RUN pip3 install ${TF_PACKAGE}${TF_PACKAGE_VERSION:+==${TF_PACKAGE_VERSION}}
